#ifndef __APP_INCLUDE_H
#define __APP_INCLUDE_H

#include "stm32f4xx.h"

/********************LOCATE CONTENT*************************/

typedef __packed struct
{
	float x_base[4];
	float y_base[4];
	float dis_base[4]; 
	/*unit:m*/
	uint8_t base_cnt;
	/*input data*/
	
	float x_tag_actual[4];
	float y_tag_actual[4];
	/*unit:m*/
	float x_tag_centroid;
	float y_tag_centroid;
	/*unit:m*/	

	/*calculated and excluded data*/
	
	uint8_t credibility[4];
	/*calculate by rssi data*/
	float x_tag_final;
	float y_tag_final;
	/*unit:m*/		
	/*final result*/
	
}Locate_InfoTypedef;
/*��λ�������ݵĽṹ��*/

/********************LOCATE CONTENT*************************/


/********************UWB CONTENT*************************/
union u16_u8
{
	uint16_t u16_;
	uint8_t u8_[2];
};

union u64_u8
{
	uint64_t u64_;
	uint8_t u8_[8];
};

#define OFFLINE_TIME 3000
#define MAX_TAG_INFO_CNT 4

typedef struct
{
	union u16_u8 addr;
	union u16_u8 x_pos;
	union u16_u8 y_pos;
	uint16_t alive_cnt;
	uint64_t ts[3];	
}TagInfoTypeDef;

typedef __packed struct
{
	uint16_t frame_ctrl;
	uint8_t seq_num;
	uint16_t dest_id;
	uint16_t dest_addr;
	uint16_t src_addr;	
}UWB_PHYHeadTypeDef;
/*UWB֡����*/



typedef __packed struct
{
	uint16_t x_pos;
	uint16_t y_pos;
	uint16_t address;
	float distance;
}UWB_AnchorInfoTypeDef;






enum
{
	MEASURE_PROCESS_FRAME = 0x0,   /*the frame which contain the x y position*/
	MEASURE_RESULT_FRAME = 0x1,		 /*the frame which contain the timestamp and x y position*/
	SEARCH_DEVICE_FRAME = 0x2,
	RESPONSE_DEVICE_FRAME = 0x3,
	TWINKLE_LIGHT_CMD = 0x4,
	ACK = 0x5,
	PING = 0x6,
	SET_POSITION = 0x7
};



enum
{
	CH1 = 0,
	CH2 = 1,
	CH3 = 2,
	CH4 = 3,
	CH5 = 4,
	CH7 = 5
};
#define ADDRESS_TAG  0xC456

 

#define ADDRESS_ANCHOR_A 0x1111
#define ADDRESS_ANCHOR_B 0x2222
#define ADDRESS_ANCHOR_C 0x3333
#define ADDRESS_ANCHOR_D 0x4444
#define ADDRESS_ANCHOR ADDRESS_ANCHOR_C

#define TERMINAL_ANCHOR_ADDRESS 0xFFF0

#define SPEED_OF_LIGHT 299702547


#define address_tx 	 0x4141
#define address_rx_A 0x5566
#define address_rx_B 0x5775
/********************UWB CONTENT*************************/


/********************TERMINAL ANCHOR CONTENT*************************/

typedef __packed struct
{
	uint16_t address;
	uint8_t channel;
	uint16_t x_pos;
	uint16_t y_pos;
	uint8_t is_led_on;
	void *next;
}Terminal_UnitInfoTypeDef;
/*the Unit infomation which collect by terminal anchor*/

/********************TERMINAL ANCHOR CONTENT*************************/



#endif



